package com.dailyblue.java.spring.ioc.mybatis.service.impl;

import com.dailyblue.java.spring.ioc.mybatis.bean.Emp;
import com.dailyblue.java.spring.ioc.mybatis.bean.JsonResult;
import com.dailyblue.java.spring.ioc.mybatis.mapper.EmpMapper;
import com.dailyblue.java.spring.ioc.mybatis.service.EmpService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class EmpServiceImpl implements EmpService {
    // 注入你所需要的对象
    @Resource
    private EmpMapper empMapper;

    @Override
    public JsonResult findAllEmp() {
        List<Emp> list = empMapper.findAllEmp();
        return new JsonResult(true, 200, null, list);
    }

    @Transactional(rollbackFor = Exception.class)
    public void change(String ename, int id) {
        // 出错
        empMapper.update(ename,id);
        // 正确
        empMapper.delete(id);
    }
}
